/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.reader.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import com.feiyue.basic.reader.pojo.FileRecord;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FileRecordDao extends Dao {
	private static final String COMPERE = "file_record";

	public FileRecordDao(Context paramContext) {
		super(paramContext);
		this.db.setTableName("file_record");
	}

	private List<FileRecord> getList(Cursor paramCursor) {
		ArrayList localArrayList = new ArrayList();
		paramCursor.moveToFirst();
		while (true) {
			if (paramCursor.isAfterLast()) {
				paramCursor.close();
				return localArrayList;
			}
			FileRecord localFileRecord = new FileRecord();
			localFileRecord.setId(paramCursor.getLong(0));
			localFileRecord.setPath(paramCursor.getString(1));
			localFileRecord.setNum(paramCursor.getInt(2));
			localFileRecord.setStartNum(paramCursor.getInt(3));
			localFileRecord.setBookId(paramCursor.getInt(4));
			localFileRecord.setCategoryId(paramCursor.getInt(5));
			localFileRecord.setChapterId(paramCursor.getInt(6));
			localFileRecord.setChapterNum(paramCursor.getInt(7));
			localArrayList.add(localFileRecord);
			paramCursor.moveToNext();
		}
	}

	public void delete(long paramLong) {
		this.db.delete(paramLong);
	}

	public void delete(String paramString) {
		List localList = getList(paramString);
		if (localList.size() == 0)
			return;
		delete(((FileRecord) localList.get(0)).getId());
	}

	public String getApi(String paramString, long paramLong) {
		return paramString + "_" + paramLong;
	}

	public List<FileRecord> getList() {
		return getList(this.db.query(new String[] { "id", "path", "num",
				"start_num", "book_id", "category_id", "chapter_id",
				"chapter_num" }, null, null, null, null, null));
	}

	public List<FileRecord> getList(int paramInt) {
		DBHelper localDBHelper = this.db;
		String[] arrayOfString1 = { "id", "path", "num", "start_num",
				"book_id", "category_id", "chapter_id", "chapter_num" };
		String[] arrayOfString2 = new String[1];
		arrayOfString2[0] = String.valueOf(paramInt);
		return getList(localDBHelper.query(arrayOfString1, "book_id = ?",
				arrayOfString2, null, null, null));
	}

	public List<FileRecord> getList(String paramString) {
		return getList(this.db.query(new String[] { "id", "path", "num",
				"start_num", "book_id", "category_id", "chapter_id",
				"chapter_num" }, "path = ?", new String[] { paramString },
				null, null, null));
	}

	public void save(FileRecord paramFileRecord) {
		List localList = getList(paramFileRecord.getBookId());
		ContentValues localContentValues = new ContentValues();
		if (localList.size() == 0) {
			localContentValues.put("num",
					Integer.valueOf(paramFileRecord.getNum()));
			localContentValues.put("path", paramFileRecord.getPath());
			localContentValues.put("start_num",
					Integer.valueOf(paramFileRecord.getStartNum()));
			localContentValues.put("book_id",
					Integer.valueOf(paramFileRecord.getBookId()));
			localContentValues.put("category_id",
					Integer.valueOf(paramFileRecord.getCategoryId()));
			localContentValues.put("chapter_id",
					Integer.valueOf(paramFileRecord.getChapterId()));
			localContentValues.put("chapter_num",
					Integer.valueOf(paramFileRecord.getChapterNum()));
			this.db.insert(localContentValues);
			return;
		}
		localContentValues.put("id", Long.valueOf(paramFileRecord.getId()));
		localContentValues
				.put("num", Integer.valueOf(paramFileRecord.getNum()));
		localContentValues.put("path", paramFileRecord.getPath());
		localContentValues.put("start_num",
				Integer.valueOf(paramFileRecord.getStartNum()));
		localContentValues.put("book_id",
				Integer.valueOf(paramFileRecord.getBookId()));
		localContentValues.put("category_id",
				Integer.valueOf(paramFileRecord.getCategoryId()));
		localContentValues.put("chapter_id",
				Integer.valueOf(paramFileRecord.getChapterId()));
		localContentValues.put("chapter_num",
				Integer.valueOf(paramFileRecord.getChapterNum()));
		this.db.update(paramFileRecord.getId(), localContentValues);
	}

	public void save(List<FileRecord> paramList) {
		Iterator localIterator = paramList.iterator();
		while (true) {
			if (!(localIterator.hasNext()))
				return;
			save((FileRecord) localIterator.next());
		}
	}
}